package cn.lll.vuehouse.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.lll.vuehouse.FORM.RolePermissionForm;
import cn.lll.vuehouse.common.ResponseResult;
import cn.lll.vuehouse.dto.RolePageDTO;
import cn.lll.vuehouse.entity.Role;
import cn.lll.vuehouse.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author:
 * @date: 2023-09-03 11:53
 * @version: 1.0
 * @description:
 */
@RestController
@RequestMapping("role")
public class RoleController {

    @Autowired
    RoleService roleService;

    @GetMapping("getRolesList")
    public ResponseResult getRolesList(){
        return roleService.getRolesList();
    }

    // 获取角色列表  list
    @GetMapping("list")
    public ResponseResult getRoleList(RolePageDTO rolePageDTO){
        return roleService.getRoleList(rolePageDTO);
    }

    // 修改角色状态  state
    @PutMapping("state")
    public ResponseResult updateRoleState(@RequestBody Role role){

        return roleService.updateRoleState(role);

    }


    // 添加、编辑角色信息  addOrUpdateRole
    @PostMapping("addOrUpdateRole")
    public ResponseResult addOrUpdateRole(@RequestBody Role role){
        Integer id = role.getId();
        if(ObjectUtil.isEmpty(id)){
            // 为空添加
            return roleService.addRole(role);
        }
        return roleService.updateRole(role);
    }

    // 根据id回显信息  getRoleById
    @GetMapping("getRoleById")
    public ResponseResult getRoleById(Integer id){
        return roleService.getRoleById(id);
    }

    // 根据id删除角色 deleteRoleById
    @GetMapping("deleteRoleById")
    public ResponseResult deleteRoleById(Integer id){
        return roleService.deleteRoleById(id);
    }

    // 添加角色权限 addRolePermission
    @PostMapping("addRolePermission")
    public ResponseResult addRolePermission(@RequestBody RolePermissionForm rolePermissionForm){
        return roleService.addRolePermission(rolePermissionForm);

    }

}
